#ifndef SCENE_H
#define SCENE_H


#include <QGraphicsScene>
#include <QGraphicsSceneEvent>
#include "mprocess.h"
#include "mtext.h"
#include "mDataManager.h"
#include "marrow.h"
#include <qdrag.h>

QT_BEGIN_NAMESPACE
class QGraphicsSceneMouseEvent;
class QMenu;
class QPointF;
class QGraphicsLineItem;
class QFont;
class QGraphicsTextItem;
class QColor;
QT_END_NAMESPACE

class scene:public QGraphicsScene
{
    Q_OBJECT

public:
    scene(QMenu *itemMenu, QObject *parent=0);
    ~scene(); //析构，不能被重载

    enum Mode {InsertItem, InsertLine,InsertText, MoveItem};
    void setLineColor(const QColor &color);
    void setTextColor(const QColor &color);
    void setItemColor(const QColor &color);
    void setFont(const QFont &font);
    bool deleteItemFromData(int id); //从数据当中删除对象
    bool deleteArrowFromData(int id);
    bool saveDataToXMLFile(QString path);


    QFont font() const{
        return myFont;
    }
    QColor textColor() const{
        return myTextColor;
    }
    QColor itemColor() const{
        return myItemColor;
    }
    QColor lineColor() const{
        return myLineColor;
    }

public slots:
    void setMode(Mode mode);
    void editorLostFocus(mText *item);

signals:
    void itemInserted(mProcess *item);
    void textInserted(QGraphicsTextItem *item);
    void itemSelected(QGraphicsItem *item);

protected:
    void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
    void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
    void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
    void dropEvent(QGraphicsSceneDragDropEvent *event);

private:
    bool isItemChange(int type);

    QMenu *myItemMenu;
    Mode myMode;
    bool leftButtonDown;
    QPointF startPoint;
    QGraphicsLineItem *line;
    QFont myFont;
    mText *textItem;
    QColor myTextColor;
    QColor myItemColor;
    QColor myLineColor;

    mDataManager *myDataManger;
};
#endif // SCENE_H
